/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <pthread.h>
#include <cutils/memory.h>

#include <utils/Log.h>

//#include <system/window.h>

#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>

#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
 #include <gui/ISurfaceComposer.h>

#define CHECK_RET() do{ if(ret) \
 printf("error:\t\tline:%d ret:%d\n", __LINE__, ret); \
 else \
    printf("OK:\t\tline:%d ret:%d\n", __LINE__, ret); \
} while(0)

using namespace android;

// get the name of the generic interface we hold a reference to
static String16 get_interface_name(sp<IBinder> service)
{
    if (service != NULL) {
        Parcel data, reply;
        status_t err = service->transact(IBinder::INTERFACE_TRANSACTION, data, &reply);
        if (err == NO_ERROR) {
            return reply.readString16();
        }
    }
    return String16();
}

    sp<IServiceManager> sm = defaultServiceManager();
    sp<IBinder> service = sm->checkService(String16("SurfaceFlinger"));
    String16 ifName = get_interface_name(service);

void sys_app_updateFrame(){
    int32_t code =  1006;
    if (service != NULL && ifName.size() > 0) {
        Parcel data, reply;
     // the interface name is first
        data.writeInterfaceToken(ifName);
        status_t ret = service->transact(code, data, &reply);
        printf("transact:%d\n", ret);
    }
}

int main(int argc, char** argv)
{

    while(1){
        sys_app_updateFrame();
        usleep(100000);
    }

    return 0;
}
